MDEV-39290 mytop use invoking login as default user on Unix
authorAquila Macedo <aquilamacedo@riseup.net>
Wed, 8 Apr 2026 14:19:44 +0000 (11:19 -0300)
committerOtto Kekäläinen <otto@debian.org>
Tue, 2 Jun 2026 00:02:02 +0000 (00:02 +0000)
On non-Windows systems, use the invoking user's login name as the
default MariaDB username instead of hardcoding root.

Resolve the username from getpwuid($<), falling back to LOGNAME, USER,
and finally root. Keep the existing root default on Windows.

This makes mytop behave more like the mysql and mariadb clients and
avoids confusing authentication failures on systems where local socket
access is configured for the OS user rather than root.

Also update the connection error text and POD to describe the actual
default behavior.

(cherry picked from commit 14502365efa17b78281e53dd1ab883f5e298a432)

Merged in upstream branch 13.0. Debian patch can be dropped when importing
new upstream major version 13.0+.

Forwarded: https://github.com/MariaDB/server/pull/4918

Gbp-Pq: Name MDEV-39290-mytop-use-invoking-login-as-default-user-on-Un.patch

scripts/mytop.sh

index f7d0fbfd6cabfd9d745205a4a2cbf70343554eb9..01ad3b73bac5768187f80cb7d013a1ffbda88b5f 100644 (file)
@@ -72,6 +72,11 @@ sub cmd_s;
 sub cmd_S;
 sub cmd_q;
 
+## Default username, matching mysql/mariadb on Unix
+my $default_db_user = $WIN
+    ? 'root'
+    : ((getpwuid($<))[0] || $ENV{LOGNAME} || $ENV{USER} || 'root');
+
 ## Default Config Values
 
 my %config = (
@@ -99,7 +104,7 @@ my %config = (
     slow          => 10,        ## slow query time
     socket        => '',
     sort          => 1,         ## default or reverse sort ("s")
-    user          => 'root',
+    user          => $default_db_user,
     fullqueries   => 0,         ## shows untruncated queries
     usercol_width => 8,         ## User column width
     dbcol_width   => 9,         ## DB column width
@@ -285,7 +290,7 @@ if (not ref $dbh)
 Cannot connect to MariaDB/MySQL server. Please check the:
 
   * database you specified "$config{db}" (default is "")
-  * username you specified "$config{user}" (default is "root")
+  * username you specified "$config{user}" (default is "$default_db_user")
   * password you specified "$config{pass}" (default is "")
   * hostname you specified "$config{host}" (default is "localhost")
   * port you specified "$config{port}" (default is 3306)
@@ -2252,7 +2257,9 @@ have two dashes `--'. Short arguments only have one '-'.
 
 =item B<-u> or B<--user> username
 
-Username to use when logging in to the MariaDB server. Default: ``B<root>''.
+Username to use when logging in to the MariaDB server. On Unix, the default
+is your login name (same as the C<mysql>/C<mariadb> client). On Windows, the
+default is ``B<root>''.
 
 =item B<-p> or B<--pass> or B<--password> I<password>
 
@@ -2386,8 +2393,9 @@ command-line arguments are processed, so your command-line arguments
 will override directives in the config file.
 
 
-Here is a sample config file C<~/.mytop> which implements the defaults
-described above.
+Here is a sample config file C<~/.mytop>. Omit C<user> to keep the built-in
+default (Unix login on non-Windows, same as C<mysql>/C<mariadb>), the line
+below is only if you want to connect as C<root> explicitly.
 
   user=root
   pass=